import xlrd
import pymongo
import decimal

myclient = pymongo.MongoClient(
    "mongodb://root:!(%2FQqi%2B9ka0y@192.168.200.108:27017/?authSource=admin&replicaSet=rs0")
mydb = myclient["bms_pre"]
mycol = mydb["BillingDetail"]

a_excel = xlrd.open_workbook("D:\\中仓-中通项目02月账单核对.xlsx")

sheet = a_excel.sheets()[0]

for i in range(1, sheet.nrows):
    cv1 = sheet.cell(i, 0).value
    cv2 = sheet.cell(i, 1).value
    print(cv1, cv2)
    myquery = {"BusinessNumber": cv1, "BillCode": "AP12BTG2UY048"}
    newvalues = {"$set": {"Amount": float(cv2)}}
    rs = mycol.update_one(myquery, newvalues)
    print("modified_count", rs.modified_count)
